#define _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    int happysum(int n)
    {
        int sum = 0;
        while (n)
        {
            int i = n % 10;
            sum += i * i;
            n /= 10;
        }
        return sum;
    }
    bool isHappy(int n) {
        int fast = happysum(n);
        int slow = n;
        while (fast != slow)
        {
            fast = happysum(happysum(fast));
            slow = happysum(slow);
        }
        return slow == 1;

    }
};